import {UIFormHelperBase} from "./UIFormHelperBase";
import {IUIForm} from "../../src/UI/IUIForm";
import UIForm from "./UIForm";
import ccclass = cc._decorator.ccclass;
import property = cc._decorator.property;
@ccclass
export class UIFromDefaultHelper extends cc.Component implements UIFormHelperBase {
    @property(cc.Canvas)
    private canvas:cc.Canvas = null;
    public get Canvas(){
        return this.canvas;
    }
    protected onLoad(): void {
        if(this.canvas == null){
            this.canvas = cc.find("GameFramework/UI/Canvas").getComponent(cc.Canvas);
        }
    }


    CreateUIForm(uiprefab, userData?): IUIForm {
        uiprefab.setParent(this.canvas.node);
        uiprefab.active = true;
        let logicbase:UIForm = uiprefab.getComponent(UIForm);
        if(logicbase == null){
            throw new Error("logicbase is null");
        }
        return logicbase;
    }

    InstantiateUIForm(uiprefab): any {
        return cc.instantiate(uiprefab);
    }

    ReleaseUIForm(UIForm: IUIForm): void {
        let uiform:UIForm = UIForm as UIForm;
        uiform.node.active = false;
    }

}